<!--跑马灯--><!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Customer</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container" id="app">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="" lay-filter="table-search">
                    <div class="layui-form-item">
                        <div class="layui-input-inline">
                            <label class="layui-form-label">状态:</label>
                            <div class="layui-input-block">
                                <select name="status" class="layui-select" >
                                    <option value="">全部</option>
                                    <option value="1">生效</option>
                                    <option value="-1">失效</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">标题</label>
                            <div class="layui-input-inline">
                                <input type="text" name="title" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">正文</label>
                            <div class="layui-input-inline">
                                <input type="text" name="content" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

    </div>
</div>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="add" auth="silent:add">添加</button>
    </div>
</script>
<table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
<script type="text/html" id="currentTableBar">
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit" auth="horseRaceLamp:edit">编辑</a>
    {{# if(d.confirm==0){ }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="confirm" auth="horseRaceLamp:confirm">再次确认</a>
    {{# } }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete" auth="horseRaceLamp:delete">删除</a>
</script>
<script id="show_game_area" type="text/html">
    {{# if(d.type==1){ }}
        所有分区
    {{# } else if(d.type ==0 ) { }}
        {{# layui.each(d.game_areas,function(index,area_code){ }}
            {{index==0?'':','}}{{getAreaName(area_code)}}
      {{# }) }}

    {{# } }}
</script>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/js/common.js?v=5" charset="utf-8"></script>
<script>
    var services= JSON.parse(localStorage.getItem('services'));
    function getAreaName(code){
        for (k in services){
            if (services[k].code == code){
                return services[k].name
            }
        }
        return code;
    }
    new Vue({
        el: "#app",
        data: {
            services: services,
        },
        mounted: function () {

            layui.use(['form', 'table','laydate'], function () {
                var isLodedTable = false;
                var $ = layui.jquery,
                    form = layui.form,
                    table = layui.table
                    ,laydate=layui.laydate;

                laydate.render({
                    elem: '#createTime0',
                    value: getYmd(0)
                });
                laydate.render({
                    elem: '#createTime1',
                    value: getYmd(1)
                });

                var loadTable = function(){
                    table.render({
                        where: form.val('table-search'),
                        elem: '#currentTableId',
                        url: '/admin/horseRaceLamp/paginate',
                        defaultToolbar: ['filter', 'print' ],
                        toolbar: '#toolbarDemo',
                        cols: [[
                            {title:"ID", field:'id'},
                            {title:"分区", field:'game_area',templet:"#show_game_area"},
                            {title:"标题", field:'title'},
                            {title:"状态", field:'status',templet: function(row){
                                if (row.status === 1 ) return '生效'
                                if (row.status === -1 ) return '失效'
                                }},
                            {title:"正文", field:'content'},
                            {field:"beginDateTime",title: '开始时间',minWidth: 160},
                            {field:"endDateTime",title: '结束时间',minWidth: 160 },
                            {field:"interval_time",title: '间隔时间(秒)' },
                            {field:"updated_at",title: '更新时间',minWidth: 160,templet:function (row) {
                                    return row.updated_at
                                }},
                            {title: '操作', minWidth: 300, align: "center", toolbar: '#currentTableBar'}
                        ]],
                        limits: [10, 15, 20, 25, 50, 100],
                        limit: 15,
                        page: true,
                        skin: 'line'
                    });
                    isLodedTable = true;
                }

                loadTable();
                // 监听搜索操作
                form.on('submit(data-search-btn)', function (data) {
                    if (!isLodedTable){
                        loadTable();
                    } else {
                        //执行搜索重载
                        table.reload('currentTableId', {
                            page: {
                                curr: 1
                            }
                            , where: form.val('table-search')
                        }, 'data');
                    }
                    return false;
                });

                /**
                 * toolbar监听事件
                 */
                table.on('toolbar(currentTableFilter)', function (obj) {
                    if(obj.event === 'add'){ //添加
                        layer.open({
                            type: 2, // page 层类型
                            area: ['100%', '100%'],
                            title: '添加',
                            shade: 0.6, // 遮罩透明度
                            shadeClose: true,
                            maxmin: true, // 允许全屏最小化
                            content: "detail.html"
                        });
                    }
                });

                table.on('tool(currentTableFilter)', function (obj) {
                    var data = obj.data;
                    if (obj.event==='edit'){
                        layer.open({
                            type: 2, // page 层类型
                            area: ['100%', '100%'],
                            title: '编辑',
                            shade: 0.6, // 遮罩透明度
                            shadeClose: true,
                            maxmin: true, // 允许全屏最小化
                            content: "detail.html?id="+data.id
                        });
                    } else if(obj.event==='confirm'){ //再次确认
                        var formData = {};
                        formData._method = 'put';
                        $.post('/admin/horseRaceLamp/confirm/'+data.id, formData, function (res) {
                            if (res.code === 0) {
                                layer.msg('确认成功', {icon: 6, time: 500}, function () {
                                    loadTable();//刷新数据
                                })
                            } else {
                                layer.msg(res.msg, {icon: 5})
                            }
                        })
                    } else if(obj.event==='delete'){
                        layer.confirm('确认删除吗?',{icon:3,title:"提示"},function () {
                            var formData = {};
                            formData._method = 'delete';
                            $.post('/admin/horseRaceLamp/'+data.id, formData, function (res) {
                                if (res.code === 0) {
                                    layer.msg('删除成功', {icon: 6, time: 500}, function () {
                                        loadTable();//刷新数据
                                    })
                                } else {
                                    layer.msg(res.msg, {icon: 5})
                                }
                            })
                        })
                    }
                });

            });
        }
    })
</script>
</body>
</html>